#include<stdio.h>
#include<stdlib.h>
#include <string.h>

void dToR(int n, char str[], int r) {
    int k = 0, d;
    char H[] = "0123456789abcdef"; //定义进制字符串
    while (n != 0) {
        d = n % r;
        str[k] = H[d]; //将余数转换为字符
        k++;
        n = n / r;
    }
    str[k] = '\0';
    //逆置字符串
    for (int i = 0, j = strlen(str) - 1; i < j; i++, j--) {
        char temp = str[i];
        str[i] = str[j];
        str[j] = temp;
    }
}


int main() {
    int n, r;
    char str[30];
    printf("请输入一个整数和进制：\n");
    scanf("%d%d", &n, &r);
    dToR(n, str, r);
    puts(str);
    return 0;
}
